<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>选择产品挂靠公司列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form  id="searchBar">
        <div class="fieldset1 clearFix">
            <div class="fieldBox">
                <div class="label">挂靠公司名称</div>
                <div class="field">
                    <input name="lnkCompNm" id="lnkCompNm" type="text" class="ui-textbox" value="">
                </div>
            </div>
           <%--  <div class="fieldBox">
                <div class="label">审核状态</div>
                <div class="field">
                     <select name="audStsCd"  id="audStsCd"   data-value="">
                     <option value="  "   selected="selected">--请选择--</option>
                     <c:forEach items="${keyValueList}" var="item">
                     	<option value="${item.key}">${item.value }</option>
                     </c:forEach>
				     </select>
                </div>
            </div> --%>
               
            <div class="formBtns notRight">
               <span id="searchBtn" class="sq-button-round">查询</span>
               <span id="clearBtn" onclick="clearBtn();" class="sq-button-round">清空</span>
               </div>
      	</div>
       </form>
 
</div>
<div id="ligergrid1" class="sq-grid"></div>
<form id="formSet">
                        <div class="fieldset1 tabel_col clearFix" style="padding-bottom:20px">
                        	<div class="caption">
		                        <span class="title">添加信息</span>
		                    </div>
		                    <div class="fieldBox col_50">
	                        	<div class="label">挂靠公司名称</span></div>
				                <div class="field">
				                   <input type="text" name="lnkCompNmReal" id="lnkCompNmReal" class="ui-textbox" value="" validate ="{required:true}" readonly="readonly"/>
				                    <span class="requiredSymbol">*</span>
				                    <input type="text" name="lnkCompId" id="lnkCompId" style="display:none">
				                </div>
				            </div>
				            <div class="fieldBox col_50">
	                        	<div class="label">公司账号</span></div>
				                <div class="field">
				                   <input type="text" name="lnkCompAccNo" id="lnkCompAccNo" class="ui-textbox" value="" validate ="{required:true}"/>
				                    <span class="requiredSymbol">*</span>
				                </div>
				            </div>
					</div>
						<div id="btnsBox" class="btnsBox" style="text-align:center">
			                <span id="saveBtn" onclick="saveInfo();" class="sq-button sq-button-round">保存</span>
			            </div>
			</form>
</div>

<script type="text/javascript">
	var grid = null;
	var prdDtlIds = '${ids}';
	var buOrgCd = '${buOrgCd}';
	//var nonAudStsCd = FlowConstant.FLOW_CHECK_STATE_NO_PASS;
	 var audStsCdList = new Array();
		if(buOrgCd!=ProjectConstant.CODE_BU_ORG_CD_CAR){
			   audStsCdList.push(CommonConstant.C_AUD_ADNWAY_CODE);
			}
	audStsCdList.push(CommonConstant.C_AUD_PASS_CODE);
	var audStsCdListArr = JSON.stringify(audStsCdList);
	$(function () {
		
		
		var form = $("#formSet").ligerForm({
			validate: true
	 	});
		
		
	    $("#ligergrid1").ligerGrid({
	    	url: '<%=path%>/project/prjlnkcomp/initList.do?audStsCdList='+audStsCdListArr+'&isBlackList=0',
	    	method : 'get',
	        columns: [
	            { display: '公司名称', name: 'lnkCompNm', minWidth: 60,
	            	 render: function (rowdata, rowindex, value){
		                    var h='';
			                    if(rowdata.audStsCd==FlowConstant.FLOW_CHECK_STATE_NON||rowdata.audStsCd==FlowConstant.FLOW_CHECK_STATE_IN){
			                    	h+='<i class="ico_flasher"></i>';
			                    }
		                        h+=rowdata.lnkCompNm;
		                    return h;
		                }},
	            { display: '成立日期', name: 'regDt', minWidth: 140 , render:renderDate,enabledSort:true},
	            { display: '企业类型', name: 'compTyp', minWidth: 60},
	            { display: '法人代表', name: 'corpRep', minWidth: 140 },
	            { display: '联系人', name: 'lnkNm', minWidth: 140 },
	            {
	                display: '操作',
	                isSort: false,
	                width: 100,
	                render: function (rowdata, rowindex, value){
	                    var h='<a class="sq-button-hasicon" href="javascript:chooseLnkComp(';
	                        h+="'"+rowdata.id+"',";
	                        h+="'"+rowdata.lnkCompNm+"'";
	                        h+=')"><i class="sqBtnIco_3"></i>选择</a>'
	                    return h;
	                }
	            }
	        ],
	        pageSize:5,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'65%',
	        heightDiff:-2,
	        //isScroll: false,
	        checkbox:true,
	        rownumbers:true
	    });
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	    $("#searchBar").ligerForm();
	
	    $("#searchBtn").click(function(event) {
	         var form = new liger.get("searchBar");
	         var data = form.getData();
	         data["lnkCompNm"] = $("#lnkCompNm").val();
	         data["audStsCd"] = $("#audStsCd").val();
	         for (name in data){
	            grid.setParm(name,data[name]);
	         };
	        grid.reload();
	    });
	});
	function chooseLnkComp(compId,compNm){
		
		
		$("#lnkCompId").val(compId);
		$("#lnkCompNmReal").val(compNm);
		
	}
	
function saveInfo(compId,compNm){
	var compId = $("#lnkCompId").val();
	var compNm = $("#lnkCompNmReal").val();
	var lnkCompAccId = $("#lnkCompAccId").val();
	var lnkCompAccNo = $("#lnkCompAccNo").val();
		if(compId){
			//更新产品的挂靠公司信息
			var params = {};
			params.lnkCmpId = compId;
			params.lnkCmpNm = compNm;
			params.lnkCompAccId =lnkCompAccId;
			params.lnkCompAccNo =lnkCompAccNo;
			params.prdDtlIds =prdDtlIds;
				$.ajax({
				type: 'post',
				dataType:'json',
				data:params,
				url: '<%=path%>/project/prjprddtl/modifyPrdLnkComp.do',
				success:function(msg){
					 if(msg.success == 1){
						 parent.grid.reload();
						parent.$.ligerDialog.close();
						parent.$(".l-dialog,.l-window-mask").css("display","none"); 
					 }else{
						 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
					 }
				}
			});
		}
	}
	
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
	function clearBtn(){
		  var form = new liger.get("searchBar");
		form.setData({
			lnkCompNm:" "
		 });
	}
	
	  
</script>

</body>
</html>